from sqlalchemy.orm import relationship, backref

from database_connection.index import Base, engine
from sqlalchemy import String, Column, Integer, Boolean

class Class(Base):  # 必须继承declaraive_base得到的那个基类
    __tablename__ = "Class"  # 必须要有__tablename__来指出这个类对应什么表，这个表可以暂时在库中不存在，SQLAlchemy会帮我们创建这个表
    id = Column(Integer, nullable=False, primary_key=True, autoincrement=True, unique=True, comment="id")
    class_label = Column(String(255), nullable=False)#分类标题

    class_blog_list = relationship("Blog", secondary="Class_Link_Blog", back_populates="blog_class_list")


    def class_to_dict(self):
        return {
            'id': self.id,
            'class_label': self.class_label,
        }

    def __init__(self, class_label):
        self.class_label = class_label

Base.metadata.create_all(engine)